// Handler 接口
interface Handler {
    void handleRequest(int request);
    void setSuccessor(Handler successor);
}

// ConcreteHandler1 类
class ConcreteHandler1 implements Handler {
    private Handler successor;

    @Override
    public void handleRequest(int request) {
        if (request >= 0 && request < 10) {
            System.out.println("ConcreteHandler1 handles request " + request);
        } else if (successor != null) {
            successor.handleRequest(request);
        }
    }

    @Override
    public void setSuccessor(Handler successor) {
        this.successor = successor;
    }
}

// ConcreteHandler2 类
class ConcreteHandler2 implements Handler {
    private Handler successor;

    @Override
    public void handleRequest(int request) {
        if (request >= 10 && request < 20) {
            System.out.println("ConcreteHandler2 handles request " + request);
        } else if (successor != null) {
            successor.handleRequest(request);
        }
    }

    @Override
    public void setSuccessor(Handler successor) {
        this.successor = successor;
    }
}

// 测试类
public class ChainOfResponsibilityTest {
    public static void main(String[] args) {
        Handler handler1 = new ConcreteHandler1();
        Handler handler2 = new ConcreteHandler2();
        handler1.setSuccessor(handler2);

        handler1.handleRequest(5);  // 输出：ConcreteHandler1 handles request 5
        handler1.handleRequest(15); // 输出：ConcreteHandler2 handles request 15
    }
}